package com.explore.demo.aop;

import com.explore.demo.cache.RedisCache;
import com.explore.demo.utils.IPUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author gaolainan
 */
@Component
@Slf4j
@Aspect
public class HistoryAspect
{

    @Resource
    private RedisCache redisCache;

    // @Around("ServiceAspect()")
    // public  Object around(ProceedingJoinPoint joinPoint) {
    //     Object[] object = joinPoint.getArgs();
    //     Object blogId = object[0];
    //     Object obj = null;
    //     try {
    //         String value = IPUtils.getIpAddr();
    //         String key = "viewCount:" + blogId;
    //         // key 为 文章ID，Value 为请求IP地址
    //         redisCache.add(key,value);
    //         obj = joinPoint.proceed();
    //     } catch (Throwable e) {
    //         e.printStackTrace();
    //     }
    //     return obj;
    // }
}
